﻿var ajaxOpt =
{
    //Ajax Form Submit
    AjaxFormSubmit: function (fromObj, funSuccess, funError) {
        fromObj.off("submit");
        fromObj.submit(function (event) {
            event.preventDefault();
            $.ajax(
                {
                    url: this.action,
                    type: this.method,
                    dataType: "json",
                    cache: false,
                    data: $(this).serialize(),
                    success: function (result) {
                        funSuccess(result);
                    },
                    error: function (data) {
                        funError(data);
                    }
                });
        });
        fromObj.trigger("submit");
    },
    //Do Ajax Action
    AjaxDoAction: function (url, funSuccess, funError) {
        $.ajax(
       {
           url: url,
           type: "post",
           dataType: "json",
           cache: false,
           data: $(this).serialize(),
           success: function (result) {
               funSuccess(result);
           },
           error: function (data) {
               funError(data);
           }
       });
    },
    AjaxDoActionWidthData: function (url, dataSource, funSuccess, funError) {
        $.ajax(
       {
           url: url,
           type: "post",
           dataType: "text",
           data: dataSource,
           cache: false,
           success: function (result) {
               funSuccess(result);
           },
           error: function (data) {
               funError(data);
           }
       });
    }
};